package com.cloudpolice.door.service.Impl;

import com.cloudpolice.door.dao.EquipParaMapper;
import com.cloudpolice.door.model.EquipParaModel;
import com.cloudpolice.door.model.InPutParam.EquipParaInsertInParam;
import com.cloudpolice.door.myenum.ParamEnum;
import com.cloudpolice.door.service.EquipParaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：梁昊，后端工程师：flyman5，前端工程师：孙耀
 * @create 2020-02-27 14:50
 * @function
 * @editLog
 */
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Service
public class EquipParaServiceImpl implements EquipParaService {
    @Autowired
    EquipParaMapper equipParaMapper;

    /**
     * 重置指定设备所有参数
     * @param sn 设备SN
     * @return
     */
    @Override
    public int insertAllEquipParam(String sn) {
        EquipParaInsertInParam equipParaInsertInParam = new EquipParaInsertInParam();
        equipParaInsertInParam.setSn(sn);
        equipParaMapper.deleteEquipParamBySnAndId(equipParaInsertInParam);
        return equipParaMapper.insertEquipParamFromDefault(sn);
    }

    /**
     * 删除设备指定参数或全部参数
     *
     * @param equipParaInsertInParam com.cloudpolice.door.model.InPutParam.EquipParaInsertInParam
     * @return 影响条数
     */
    @Override
    public int deleteEquipParamBySnAndId (EquipParaInsertInParam equipParaInsertInParam) {
        return equipParaMapper.deleteEquipParamBySnAndId(equipParaInsertInParam);
    }


    /**
     * 加入设备参数
     *
     * @param equipParaInsertInParam com.cloudpolice.door.model.InPutParam.EquipParaInsertInParam
     * @return 设备参数列表
     */
    @Override
    public int insertEquipParam (EquipParaInsertInParam equipParaInsertInParam) {
        final int i = equipParaMapper.insertEquipParamBeforeCheck(equipParaInsertInParam);
        if (i > 0)
            return equipParaMapper.updateEquipBySnAndId(equipParaInsertInParam);
        else
            return equipParaMapper.insertEquipParam(equipParaInsertInParam);
    }

    /**
     * 根据设备SN号，得到设备参数
     *
     * @param sn 设备SN
     * @return 设备参数列表
     */
    @Override
    public List<EquipParaModel> selectEquipParamsBySn(String sn) {
        return equipParaMapper.selectEquipParamsBySn(sn);
    }
}
